package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.widget.RelativeLayout;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.adapter.MyDeskmediaFragmentAdapter;
import com.hzdesk.media.koreabatchmatvector.config.RxBusUtil;
import com.hzdesk.media.koreabatchmatvector.custom.NoScrollViewPager;
import com.hzdesk.media.koreabatchmatvector.logic.contract.DialogContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.DialogPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.RxBus;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/6/22.
 * 杭州席媒科技有限公司  Developers  刘传华  14
 * 佛祖镇楼 bug辟易
 */

public class DialogActivity extends BaseActivity implements DialogContract.IDialogView {

    @BindView(R.id.activity_dialog_viewpager)
    NoScrollViewPager activityDialogViewpager;
    @BindView(R.id.activity_dialog_rl_bg)
    RelativeLayout activityDialogRlBg;
    private DialogPersenter mDialogPersenter = new DialogPersenter(this);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
        ButterKnife.bind(this);
        initDate();
    }

    private void initDate() {
        MyDeskmediaFragmentAdapter mMyDeskmediaFragmentAdapter = new MyDeskmediaFragmentAdapter(getSupportFragmentManager());
        activityDialogViewpager.setAdapter(mMyDeskmediaFragmentAdapter);
        mDialogPersenter.initViewPagerDate(activityDialogViewpager);
        mDialogPersenter.initListen();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        int Dialog_viewpage_index = intent.getIntExtra("Dialog_viewpage_index", 0);
        switch (Dialog_viewpage_index) {
            case RxBusUtil.CHANGE_SET_FRAGMENT: //0 系统设置页面
                // activityDialogViewpager.setCurrentItem(RxBusUtil.CHANGE_SET_FRAGMENT,false);
                viewpagerCurrentItemShow(RxBusUtil.CHANGE_SET_FRAGMENT);
                break;
            case RxBusUtil.CHANGE_VIDEO_LIST_FRAGMENT:
                viewpagerCurrentItemShow(RxBusUtil.CHANGE_VIDEO_LIST_FRAGMENT);
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        activityDialogRlBg.setBackgroundResource(updateBg[selector]);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxBus.getInstance().unSubcribe();
    }

    @Override
    public void viewpagerCurrentItemShow(int pager) {
        activityDialogViewpager.setCurrentItem(pager, false);
    }

    @Override
    public int getViewpageIndex() {
        return getIntent().getIntExtra("Dialog_viewpage_index", 0);
    }

    @Override
    public void finshPager() {
        finish();
    }
}
